package com.aliwo.design.patterns.strategy.impl;

import com.aliwo.design.patterns.strategy.ICouponDiscount;

import java.math.BigDecimal;

/**
 * @author xuyayuan
 * @description 直减优惠券实现逻辑
 * @date 2021/9/9 11:36
 */
public class ZJCouponDiscountImpl implements ICouponDiscount<Double> {

    /**
     * 功能描述: 直减优惠券逻辑
     *   * 直减计算
     *      * 1. 使用商品价格减去优惠价格
     *      * 2. 最低支付金额1元
     * @author xuyayuan
     * @param couponInfo
     * @param skuPrice
     * @return java.math.BigDecimal
     */
    @Override
    public BigDecimal discountAmount(Double couponInfo, BigDecimal skuPrice) {
        BigDecimal discountAmount = skuPrice.subtract(new BigDecimal(couponInfo));
        if (discountAmount.compareTo(BigDecimal.ZERO) < 1) {
            return BigDecimal.ONE;
        }
        return discountAmount;
    }
}
